package com.hemaapp.yjnh.activity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.hemaapp.hm_FrameWork.HemaNetTask;
import com.hemaapp.hm_FrameWork.result.HemaBaseResult;
import com.hemaapp.yjnh.BaseFragmentActivity;
import com.hemaapp.yjnh.R;
import com.hemaapp.yjnh.adapter.TabViewPagerAdapter;
import com.hemaapp.yjnh.fragment.FootPrintListFragment;

/**我的足迹
 * @author ZhangGuiyou
 * Date: 2015-07-30 09:35
 * Mod Date: 2016-01-04 13:38
 */
public class FootprintActivity extends BaseFragmentActivity implements OnClickListener{

	@Bind(R.id.title_left_btn)
	ImageButton titleLeftBtn;
	@Bind(R.id.title_right_btn)
	Button titleRightBtn;
	@Bind(R.id.title_text)
	TextView titleText;
	@Bind(R.id.layout_tab)
	TabLayout layoutTab;
	@Bind(R.id.viewpager)
	ViewPager viewpager;

	private TabViewPagerAdapter pagerAdapter;
	List<Fragment> fragments = new ArrayList<>();
	private FootPrintListFragment liangkuFragment = new FootPrintListFragment();
	private FootPrintListFragment farmerFragment = new FootPrintListFragment();
	private FootPrintListFragment leleFragment = new FootPrintListFragment();
	private FootPrintListFragment zouzouFragment = new FootPrintListFragment();
	private FootPrintListFragment cunyouFragment = new FootPrintListFragment();
	private FootPrintListFragment OrangicFragment = new FootPrintListFragment();
	private FootPrintListFragment landmarkFragment = new FootPrintListFragment();
	private FootPrintListFragment techanFragment = new FootPrintListFragment();
	private FootPrintListFragment nongxuFragment = new FootPrintListFragment();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_collection);
		ButterKnife.bind(this);
		super.onCreate(savedInstanceState);
		initDatas();
	}

	private void initDatas() {
		List<String> titles = new ArrayList<>();
		titles.add("粮库");
		titles.add("田家");
		titles.add("乐乐");
		titles.add("走走");
		titles.add("村游");
		titles.add("有机");
		titles.add("地标");
		titles.add("特产");
		titles.add("农需");
		fragments.add(liangkuFragment);
		fragments.add(farmerFragment);
		fragments.add(leleFragment);
		fragments.add(zouzouFragment);
		fragments.add(cunyouFragment);
		fragments.add(OrangicFragment);
		fragments.add(landmarkFragment);
		fragments.add(techanFragment);
		fragments.add(nongxuFragment);
		//获取类型	1：田家     2：有机    3：地标    4：村游    6：特产    7：走走    8：农需    9：乐乐    11：粮库
		liangkuFragment.setKeytype("11");
		farmerFragment.setKeytype("1");
		leleFragment.setKeytype("9");
		zouzouFragment.setKeytype("7");
		cunyouFragment.setKeytype("4");
		OrangicFragment.setKeytype("2");
		landmarkFragment.setKeytype("3");
		techanFragment.setKeytype("6");
		nongxuFragment.setKeytype("8");

		pagerAdapter = new TabViewPagerAdapter(getSupportFragmentManager(), fragments, titles);
		viewpager.setAdapter(pagerAdapter);
		viewpager.setOffscreenPageLimit(9);
		layoutTab.setTabMode(TabLayout.MODE_SCROLLABLE);
		layoutTab.setupWithViewPager(viewpager);
		layoutTab.setTabsFromPagerAdapter(pagerAdapter);
	}

	@Override
	protected void findView() {
	}

	@Override
	protected void getExras() {
	}

	@Override
	protected void setListener() {
		titleText.setText("我的足迹");
		titleRightBtn.setText("清空");
	}

	@Override
	protected void callBeforeDataBack(HemaNetTask hemaNetTask) {

	}

	@Override
	protected void callAfterDataBack(HemaNetTask hemaNetTask) {

	}

	@Override
	protected void callBackForServerSuccess(HemaNetTask hemaNetTask, HemaBaseResult hemaBaseResult) {

	}

	@Override
	protected void callBackForServerFailed(HemaNetTask hemaNetTask, HemaBaseResult hemaBaseResult) {

	}

	@Override
	protected void callBackForGetDataFailed(HemaNetTask hemaNetTask, int i) {

	}

	@OnClick({R.id.title_left_btn, R.id.title_right_btn})
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.title_left_btn:
				finish();
				break;
			case R.id.title_right_btn:
				int index = viewpager.getCurrentItem();
				((FootPrintListFragment)fragments.get(index)).clearHistory();
				break;
		}
	}
}
